package com.util.annotate.demo.service;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Proxy;
import java.util.Properties;

/**
 * 读取工厂配置方法
 */
public class HrsConfigFactory {
    public HrsConfigFactory() {
    }

    /**
     * 读取方法
     * @param inputStream
     * @return
     */
    public static HrsConfigService readProperties(final InputStream inputStream) {

        final Properties properties = new Properties();
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            System.out.println("加载输入流错误");
            return null;
        }

        // java 代理机制
        return (HrsConfigService) Proxy
                .newProxyInstance(HrsConfigService.class.getClassLoader(), new Class[]{HrsConfigService.class},
                        new PropertyInvocationHandler(properties));
    }
}
